require("NodeManager")
HeroData={
hero58={totalHP=456,currentHP=456,totalSP=200,attack=100,defend=10},
hero70={totalHP=156,currentHP=156,totalSP=200,attack=10,defend=10},
hero71={totalHP=156,currentHP=156,totalSP=200,attack=10,defend=10},
hero72={totalHP=156,currentHP=156,totalSP=200,attack=10,defend=10},
hero73={totalHP=156,currentHP=156,totalSP=200,attack=10,defend=10},
hero74={totalHP=156,currentHP=156,totalSP=200,attack=10,defend=10},
hero75={totalHP=156,currentHP=156,totalSP=200,attack=10,defend=10},
hero76={totalHP=156,currentHP=156,totalSP=200,attack=10,defend=10},
hero77={totalHP=156,currentHP=156,totalSP=200,attack=10,defend=10},
hero78={totalHP=156,currentHP=156,totalSP=200,attack=10,defend=10},
hero79={totalHP=156,currentHP=156,totalSP=200,attack=10,defend=10}
}

HeroFunc={}
Hero={}
HeroFunc.__index=HeroFunc
setmetatable(Hero, HeroFunc)

HeroFunc.release = function(self)
  print("HeroFunc.release", self)
  self.parent:removeChild(self.normalView, true)
  self.parent:removeChild(self.hpView, true)
  self.parent:removeChild(self.spView, true)
  self.parent:removeChild(self.bkHpView, true)
end

HeroFunc.create = function(parent, name, position)
  hero={}
  setmetatable(hero, HeroFunc)
 
  hero.parent=parent 
  hero.data = {}
  for k,v in pairs(HeroData[name]) do
    hero.data[k] = v
  end
  
  CCSpriteFrameCache:sharedSpriteFrameCache():addSpriteFramesWithFile(string.format("%s.plist", name))
  local sp = CCSprite:createWithSpriteFrameName(string.format("%s_std_1.png", name))
  sp:setPosition(position)
  sp:setFlipX(flip)
  parent:addChild(sp)
  NodeManager:addObject(name, p)

  local bksp = CCSprite:create("war_hp_bg.png")
  local hpsp = CCSprite:create("war_hp.png")
  local spsp = CCSprite:create("war_sp.png")
  local hpbar = CCProgressTimer:create(hpsp)
  local spbar = CCProgressTimer:create(spsp)
  hpbar:setType(kCCProgressTimerTypeBar)
  hpbar:setPercentage(100.0)
  hpbar:setMidpoint(ccp(0,0))
  hpbar:setBarChangeRate(ccp(1, 0))
  spbar:setType(kCCProgressTimerTypeBar)
  spbar:setPercentage(100.0)
  spbar:setMidpoint(ccp(0,0))
  spbar:setBarChangeRate(ccp(1, 0))

  parent:addChild(bksp)
  parent:addChild(hpbar)
  parent:addChild(spbar)
  bksp:setPosition(position.x,position.y+80)
  hpbar:setPosition(position.x,position.y+80+5)
  spbar:setPosition(position.x,position.y+80-5)
  --NodeManager:addObject("hpbar", hpbar)
  --NodeManager:addObject("spbar", hpbar)

  --NodeManager:addObject(string.format("%s-normal", name), sp)
  --NodeManager:addObject(string.format("%s-hp", name), hpbar)
  --NodeManager:addObject(string.format("%s-sp", name), spbar)
  
  hero.normalView = sp 
  hero.hpView = hpbar
  hero.spView = spbar
  hero.bkHpView = bksp 

  NodeManager:addObject(name, hero)
  return hero
end
